Gnc.DepartmentBtnEditSelect = function () {
    Gnc.DepartmentBtnEditSelect.superclass.constructor.call(this);
    this.set({
        border: 1,
        showClose:true,
        emptyText: '请选择...',
        valueField: "Id",
        textField: "Name",
        allowInput:false
    });
};
mini.extend(Gnc.DepartmentBtnEditSelect, mini.ButtonEdit, {
    uiCls: "gnc-departmentbtneditselect",
    openWinUrl:bootPATH+'Js/Common/Org/DepartmentBtnEditPanel-mini.aspx',
    showClose:true,
    selectedItem:null,
    _create: function () {
       Gnc.DepartmentBtnEditSelect.superclass._create.call(this);
        this.on('buttonclick',function(record){
            this.onButtonEdit(this.getValue(),this.getText());
        },this);
        
        this.on('valuechanged',function(record){
            var rec = {
                        Id:record.Id,
                        Name:record.Name
                    };
            this.selectedItem = rec;
            this.fire('departmentValueChangedSelected',this.selectedItem);
        },this);
        this.on('closeclick',function(e){
            var obj = e.sender;
            this.removeAll();
            this.fire('departmentCleared');
        },this);
    },
    
    removeAll:function(){
        this.setNameValue('','');
    },
    setNameValue:function(name,value){
        this.setValue(value);
        this.setText(name);
    },
    setData:function(Id,Name){
        this.setNameValue(Name,Id);
    },
    load:function(){
        var rec = {
            Id: this.getValue(),
            Name: this.getText()
        };
        this.selectedItem = rec;
        this.fire('departmentValueChangedSelected',this.selectedItem);
    },
    onButtonEdit:function(Id,Name) {
        var btnEdit = this;
        mini.open({
            url: this.openWinUrl,
            showMaxButton: false,
            title: "选择部门",
            width: 380,
            height:400,
            onload: function () {
                var iframe = this.getIFrameEl();
                //传递创建参数
                //iframe.contentWindow.setData(Id,Name);
            },
            ondestroy: function (data) {                    
                if (data.action == "ok") {
                    /*var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.getData();*/
                    /*data = mini.clone(data);*/
                    if (data) {
                        btnEdit.setValue(data.id);
                        btnEdit.setText(data.Name);
                    }
                }
                //btnEdit.load();
            }
        });
    }
});
mini.regClass(Gnc.DepartmentBtnEditSelect, "Gnc.DepartmentBtnEditSelect");